/*
 * grav.cpp
 *
 *  Created on: Mar 24, 2012
 *      Author: Stephen
 */


#include "grav.h"

Obj::Obj(double posx, double posy)
{
	pos.x = posx;
	pos.y = posy;
	vel.x = vel.y = acc.x = acc.y = 0;
	time = 0;
}

Obj::Obj(double posx, double posy, double time)
{
	pos.x = posx;
	pos.y = posy;
	vel.x = vel.y = acc.x = acc.y = 0;
	this->time = time;
}

Obj::Obj(double posx, double posy, double velx, double vely, double accx, double accy)
{
	pos.x = posx;
	pos.y = posy;
	vel.x = velx;
	vel.y = vely;
	acc.x = accx;
	acc.y = accy;
	time = 0;
}

Obj::Obj(double posx, double posy, double velx, double vely, double accx, double accy, double time)
{
	pos.x = posx;
	pos.y = posy;
	vel.x = velx;
	vel.y = vely;
	acc.x = accx;
	acc.y = accy;
	this->time = time;
}

rect Obj::position()
{
	return pos;
}

rect Obj::velocity()
{
	return vel;
}

rect Obj::acceleration()
{
	return acc;
}

void Obj::settime(double time)
{
	this->time = time;
}

double Obj::gettime()
{
	return time;
}

rect Obj::update()
{
	/* x = x + vt + 0.5at^2
	 * v = v + at
	 */
	if(vel.x != 0 && acc.x != 0)
	{
		pos.x = (double)(pos.x + vel.x * time + 0.5f * acc.x * time * time);
	}
	if(vel.y != 0 && acc.y != 0)
	{
		pos.y = (double)(pos.y + vel.y * time + 0.5f * acc.y * time * time);
	}

	if(acc.x != 0)
	{
		vel.x = vel.x + acc.x * time;
	}
	if(acc.y != 0)
	{
		vel.y = vel.y + acc.y * time;
	}

	return pos;
}

rect Obj::update(double time)
{
	/* x = x + vt + 0.5at^2
	 * v = v + at
	 */
	if(vel.x != 0 && acc.x != 0)
	{
		pos.x = (double)(pos.x + vel.x * time + 0.5f * acc.x * time * time);
	}
	if(vel.y != 0 && acc.y != 0)
	{
		pos.y = (double)(pos.y + vel.y * time + 0.5f * acc.y * time * time);
	}

	if(acc.x != 0)
	{
		vel.x = vel.x + acc.x * time;
	}
	if(acc.y != 0)
	{
		vel.y = vel.y + acc.y * time;
	}

	return pos;
}

void Obj::veloc(double x, double y)
{
	vel.x = x;
	vel.y = y;
}

void Obj::velocx(double x)
{
	vel.x = x;
}

void Obj::velocy(double y)
{
	vel.y = y;
}

void Obj::accel(double x, double y)
{
	acc.x = x;
	acc.y = y;
}

void Obj::accelx(double x)
{
	acc.x = x;
}

void Obj::accely(double y)
{
	acc.y = y;
}
